import axios from 'axios';
import Vue from 'vue';
import router from "../router";
//axios请求配置
axios.defaults.headers.post['Content-Type'] = 'application/json';
Vue.prototype.$axios = axios;
// axios.defaults.baseURL = 'http://localhost:8839/';
axios.defaults.timeout = 10000
const request = axios.create({
    baseURL: 'http://localhost:8839/',
    timeout: 10000
});



export function get(url,params={}){
    return new Promise((resolve,reject) => {
        axios.get(url,{
            params:params
        })
            .then(response => {
                resolve(response.data);
            })
            .catch(err => {
                reject(err)
            })
    })
}

export function post(url,data = {}){
    return new Promise((resolve,reject) => {
        axios.post(url,data)
            .then(response => {
                resolve(response.data);
            },err => {
                reject(err)
            })
    })
}

export function put(url,data = {}){
    return new Promise((resolve,reject) => {
        axios.put(url,data)
            .then(response => {
                resolve(response.data);
            },err => {
                reject(err)
            })
    })
}

export default request;
